package com.wzw.wx.api.service;

import com.wzw.wx.api.tools.PDF2Png;
import com.wzw.wx.api.tools.Word2PDF;
import com.wzw.wx.api.type.TransType;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

@Service
public class OfficeTransService {
    public String transOfficeFile(MultipartFile file){
        try {
            String filename = file.getOriginalFilename();
            String extName = filename.substring(filename.lastIndexOf(".") + 1);
            if (TransType.pdf.toString().equals(extName))
                return new PDF2Png().executeInputStream(file.getInputStream());
            else if (TransType.doc.toString().equals(extName) || TransType.docx.toString().equals(extName))
                return new Word2PDF().executeInputStream(file.getInputStream()); //"C:\\Users\\WuZewen\\Desktop\\文档转换格式测试\\test.docx"
            else
                return "仅支持word和pdf";
        }catch (Exception e){
            return "文件转换失败";
        }
    }
}
